package com.example.wsh.worddemo.Users_Fragment;

import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Html;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.method.LinkMovementMethod;
import android.text.style.URLSpan;
import android.view.View;
import android.widget.TextView;

import com.example.wsh.worddemo.R;
import com.jaeger.library.StatusBarUtil;

public class About extends AppCompatActivity {

    private TextView to_github;
    private String github_url;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_about);
        StatusBarUtil.setTranslucent(About.this);
        ActionBar actionBar  = getSupportActionBar();
        if(actionBar != null){
            actionBar.hide();
        }
        to_github  = findViewById(R.id.to_github);
        to_github.setText(Html.fromHtml("<a href=\"https://github.com/YSXCC\">YSXCC</a>"));
        // 在单击链接时凡是有要执行的动作，都必须设置MovementMethod对象
        to_github.setMovementMethod(LinkMovementMethod.getInstance());
        CharSequence text  =  to_github.getText();
        if (text instanceof Spannable){
            int  end  =  text.length();
            Spannable sp  =  (Spannable)to_github.getText();
            URLSpan[] urls = sp.getSpans( 0 , end, URLSpan.class );
            SpannableStringBuilder style = new  SpannableStringBuilder(text);
            style.clearSpans(); // should clear old spans
            for (URLSpan url : urls){
                URLSpan myURLSpan=   new  URLSpan(url.getURL());
                style.setSpan(myURLSpan,sp.getSpanStart(url),sp.getSpanEnd(url),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
            to_github.setText(style);
        }
    }
}
